package net.entelijan.cobean.examples.showcase.checkbox;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import net.entelijan.cobean.core.ICobean;
import net.entelijan.cobean.toggle.DefaultToggleInitializer;
import net.entelijan.scf.IShowcase;

public class ToggleShowcase implements IShowcase<TogglePanel> {

	private ICobean<Boolean> checkBoxCobean;

	public ToggleShowcase() {
		super();
	}

	@Override
	public void init(final TogglePanel panel) {

		{
			DefaultToggleInitializer init = new DefaultToggleInitializer();
			init.setCoToggleButton(panel.getCheckBox());
			checkBoxCobean = init.initialize();
		}

		panel.getShowModelButton().addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(panel, "checkBoxCobean: "
						+ checkBoxCobean.getValue());
			}

		});
		panel.getToggleCobeanButton().addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				if (checkBoxCobean.getValue()) {
					checkBoxCobean.setValue(false);
				} else {
					checkBoxCobean.setValue(true);
				}
			}

		});
	}

}
